package Gestion_article;

import com.j256.ormlite.logger.Logger;
import com.mysql.jdbc.Connection;
import java.awt.Color;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author GSK
 */
public class CRUD_article extends javax.swing.JFrame {
Connection connexion;
    /**
     * Creates new form CRUD_article
     */
    public CRUD_article() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelArticle = new javax.swing.JLabel();
        jLabelPrix = new javax.swing.JLabel();
        jLabelQuantité = new javax.swing.JLabel();
        jLabelDescCourte = new javax.swing.JLabel();
        jLabelDecLongue = new javax.swing.JLabel();
        jButtonAjouter = new javax.swing.JButton();
        jButtonModifier = new javax.swing.JButton();
        jTextFieldPrix = new javax.swing.JTextField();
        jTextFieldQuantite = new javax.swing.JTextField();
        jLabelMarque = new javax.swing.JLabel();
        jLabelMarqueActuelle = new javax.swing.JLabel();
        jLabelDescCourteActuelle = new javax.swing.JLabel();
        jLabelDescLongueActuelle = new javax.swing.JLabel();
        jPanelAnciennePhoto = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaEtat = new javax.swing.JTextArea();
        jTextFieldID = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelArticle.setText("haricots");

        jLabelPrix.setText("Prix");

        jLabelQuantité.setText("Quantité");

        jLabelDescCourte.setText("Description Courte");

        jLabelDecLongue.setText("Description Longue");

        jButtonAjouter.setText("Ajouter");

        jButtonModifier.setText("Modifier");
        jButtonModifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonModifierActionPerformed(evt);
            }
        });

        jLabelMarque.setText("Marque");

        jLabelMarqueActuelle.setText("jLabel3");

        jLabelDescCourteActuelle.setText("jLabel4");

        jLabelDescLongueActuelle.setText("jLabel5");

        javax.swing.GroupLayout jPanelAnciennePhotoLayout = new javax.swing.GroupLayout(jPanelAnciennePhoto);
        jPanelAnciennePhoto.setLayout(jPanelAnciennePhotoLayout);
        jPanelAnciennePhotoLayout.setHorizontalGroup(
            jPanelAnciennePhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 133, Short.MAX_VALUE)
        );
        jPanelAnciennePhotoLayout.setVerticalGroup(
            jPanelAnciennePhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 138, Short.MAX_VALUE)
        );

        jTextAreaEtat.setColumns(20);
        jTextAreaEtat.setRows(5);
        jScrollPane1.setViewportView(jTextAreaEtat);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(jLabelArticle, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelAnciennePhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldID, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabelDescCourte)
                            .addGap(26, 26, 26))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabelPrix, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabelQuantité, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelMarque, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(73, 73, 73)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelDecLongue)
                        .addGap(26, 26, 26)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldPrix, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabelDescCourteActuelle, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabelMarqueActuelle, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabelDescLongueActuelle, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jTextFieldQuantite, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(397, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(175, 175, 175)
                        .addComponent(jButtonAjouter)
                        .addGap(50, 50, 50)
                        .addComponent(jButtonModifier))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(189, 189, 189)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelArticle, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPrix)
                    .addComponent(jTextFieldPrix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelAnciennePhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabelQuantité)
                                .addComponent(jTextFieldQuantite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(34, 34, 34)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelMarqueActuelle)
                                    .addComponent(jLabelMarque))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelDescCourteActuelle)
                                    .addComponent(jLabelDescCourte))))
                        .addGap(36, 36, 36)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelDecLongue)
                            .addComponent(jLabelDescLongueActuelle))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonAjouter)
                            .addComponent(jButtonModifier))))
                .addGap(33, 33, 33)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(155, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonModifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifierActionPerformed
        // TODO add your handling code here:
        if(this.connexion != null){
            if(!jTextFieldPrix.equals("")){
                try{
                    Statement maRequete = this.connexion.createStatement();
                 int nbTuplesModifies=   maRequete.executeUpdate("UPDATE article SET prix_ht_article='"+jTextFieldPrix.getText()+"' where id="+jTextFieldID.getText());
                    if(nbTuplesModifies == 1){
                         jTextAreaEtat.setForeground(Color.green);
                        jTextAreaEtat.setText("Modif réussie !!");
                        
                    }else{
                         jTextAreaEtat.setForeground(Color.red);
                        jTextAreaEtat.setText("La modification à échouée !!");
                    }
                }catch(SQLException ex){
                    jTextAreaEtat.setForeground(Color.red);
                    jTextAreaEtat.setText("Erreur, l'éxécution de la requête est un échec !!");
                    //Logger.getLogger(CRUD_article.class.getName()).log(Level.SEVERE,null,ex);
                }
            }else{
                jTextAreaEtat.setForeground(Color.red);
                jTextAreaEtat.setText("Erreur, le champ Nom n'est pas renseigné !!");
            }
        }
        
        
       
        
    }//GEN-LAST:event_jButtonModifierActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CRUD_article.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CRUD_article.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CRUD_article.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CRUD_article.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CRUD_article().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAjouter;
    private javax.swing.JButton jButtonModifier;
    private javax.swing.JLabel jLabelArticle;
    private javax.swing.JLabel jLabelDecLongue;
    private javax.swing.JLabel jLabelDescCourte;
    private javax.swing.JLabel jLabelDescCourteActuelle;
    private javax.swing.JLabel jLabelDescLongueActuelle;
    private javax.swing.JLabel jLabelMarque;
    private javax.swing.JLabel jLabelMarqueActuelle;
    private javax.swing.JLabel jLabelPrix;
    private javax.swing.JLabel jLabelQuantité;
    private javax.swing.JPanel jPanelAnciennePhoto;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaEtat;
    private javax.swing.JTextField jTextFieldID;
    private javax.swing.JTextField jTextFieldPrix;
    private javax.swing.JTextField jTextFieldQuantite;
    // End of variables declaration//GEN-END:variables
}
